/*
 * @Author: chengwenixng
 * @Date: 2021-08-07 19:52:17
 * @LastEditors: g05047
 * @LastEditTime: 2021-08-10 11:48:25
 * @Description: file content
 */
import request from '@utils/request';
import * as actionTypes from './actionType'
import { message } from 'antd';

//获取所有数据
export const getPersonalCenterRequest  = () => {
    return (dispatch) => {
        request('POST', '/api/server/web/rest/user/personalCenter', {
            cmd: 'personalCenter',
            type: 'request',
            request: {}
        }).then(obj => {
            let res = obj.response;
            if (res.res) {
                dispatch(getPersonalCenterReducer(res.message));
            } else {
                message.error('获取数据失败！' + res.exception, 1);
            }
        }).catch(err => console.log(err));
    }
}
const getPersonalCenterReducer = (personalCenter) => ({
    type: actionTypes.PERSONALCENTER,
    personalCenter
})
//更换头像
export const modifyUserHeadPortrait = (headPortraitPath) => {
    return (dispatch) => {
        request('POST', '/api/server/web/rest/user/modifyUserHeadPortrait', {
            cmd: 'modifyUserHeadPortrait',
            type: 'request',
            request: {
                headPortraitPath
            }
        }).then(obj => {
            let res = obj.response;
            if (res.res) {
                dispatch(getPersonalCenterRequest())
            } else {
                message.error('更换头像失败' + res.exception, 1);
            }
        }).catch(err => console.log(err));
    }
}
//完善个人信息
export const getPersonalInformation = (values) => {
    return (dispatch) => {
        request('POST', '/api/server/web/rest/user/getPersonalInformation', {
            cmd: 'getPersonalInformation',
            type: 'request',
            request: {
                ...values
            }
        }).then(obj => {
            let res = obj.response;
            if (res.res) {
                message.success("提交成功！")
                dispatch(getPersonalCenterRequest())
            } else {
                message.error('提交失败' + res.exception, 1);
            }
        }).catch(err => console.log(err));
    }
}
